<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="https://www.thymeleaf.org">
<head>
    <title>游玩记录管理</title>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" type="text/css" media="all" href="/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css">
    <script type="text/javascript" src="/js/jquery-3.6.0.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/layui/layui.js"></script>
</head>
<script>
    function updateValues(ID) {
        $("#UpdateID").val(ID);
    }
    function deleteValues(ID) {
        $("#DeleteID").val(ID);
    }
    function findInto_roomByName() {
        var name = $("#searchRRecord").val();
        data = {
            name: name
        }
        $.ajax({
            url: "findInto_roomByRoom",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function findInto_roomByAccount() {
        var account = $("#searchARecord").val();
        data = {
            account: account
        }
        $.ajax({
            url: "findInto_roomByAccount",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function FindInto_roomFlag() {
        var flag = $("#into_roomFlag").val();
        data = {
            flag: flag
        }
        $.ajax({
            url: "findInto_roomByFlag",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
    }
    function DeleteRecord() {
        var id = $("#DeleteID").val();
        data = {
            id: id
        }
        $.ajax({
            url: "admin/deleteRecordByID",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
    function FinishRecord() {
        var id = $("#UpdateID").val();
        data = {
            id: id
        }
        $.ajax({
            url: "admin/updateRecordByID",
            type: "Post",
            data: data,
            datatype: "html",
            success: function(data, status) {
                $("#roomInformation").replaceWith(data);
            }
        })
        setTimeout(function () {
            location.reload();
        }, 3000);
    }
</script>
<body>
<div class="container mt-3" id="roomInformation">
    <h2>游玩记录管理界面</h2>
    <br>
    <ul class="nav nav-pills" role="tablist">

        <li class="navbar-form navbar-left" role="search">
            <a class="form-group">
                <input type="text" class="form-control" id="searchRRecord" placeholder="搜索房间号"/>
            </a>
        </li>
        <li>
            <button type="submit" class="btn btn-default" onclick="findInto_roomByName()">搜索</button>
        </li>
        <li class="navbar-form navbar-left" role="search">
            <a class="form-group">
                <input type="text" class="form-control" id="searchARecord" placeholder="搜索玩家号"/>
            </a>
        </li>
        <li>
            <button type="submit" class="btn btn-default" onclick="findInto_roomByAccount()">搜索</button>
        </li>

        <div class="flag">
            <select id="into_roomFlag" onchange="FindInto_roomFlag()" type="button" class="btn btn-light btn-sm">
                <option>按照房间状态筛选</option>
                <option value="7">全部</option>
                <option value="0">不在房间</option>
                <option value="1">在房间</option>
                <option value="2">游玩中</option>
            </select>
        </div>

    </ul>
    <div class="tab-content">
        <div id="home" class="container tab-pane active"><br>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>游玩记录号</th>
                    <th>用户</th>
                    <th>房间名</th>
                    <th>进入房间时间</th>
                    <th>游玩开始时间</th>
                    <th>离开房间时间</th>
                    <th>是否在房间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="record:${records}">
                    <td th:text="${record.id}"></td>
                    <td th:text="${record.account}"></td>
                    <td th:text="${record.name}"></td>
                    <td th:text="${record.enterTime}"></td>
                    <td th:text="${record.playTime}"></td>
                    <td th:text="${record.leaveTime}"></td>
                    <td th:if="${record.flag}==0">不在房间</td>
                    <td th:if="${record.flag}==1">在房间</td>
                    <td th:if="${record.flag}==2">游玩中</td>
                    <td>
                        <button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#fire" th:onclick="|javascrip:deleteValues('${record.id}')|">删除记录</button>
                        <button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#modify" th:onclick="|javascrip:updateValues('${record.id}')|" th:if="${record.flag}==1">开始游玩</button>
                        <button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#modify" th:onclick="|javascrip:updateValues('${record.id}')|" th:if="${record.flag}==2">结束游玩</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal Fire" id="fire">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h3 class="modal-title">删除记录</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">记录号</td><td><input readonly="readonly" id="DeleteID" name="DeleteID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">是否删除该记录？</td><td style="height:32px;width:300px;font-size:22px">永久删除该记录（真的很久）</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="DeleteRecord()">是</button>
            </div>

        </div>
    </div>
</div>

<div class="modal alter" id="modify">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width:650px">

            <div class="modal-header">
                <h4 class="modal-title">更新游玩记录</h4>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <div class="modal-body">
                <table class="table table-bordered">
                    <thead>
                    </thead>
                    <tbody>
                    <tr>
                        <td style="font-size:22px">记录号</td><td><input id="UpdateID" name="UpdateID" style="height:32px;width:300px;font-size:22px"></td>
                    </tr>
                    <tr>
                        <td style="font-size:22px">更新游玩记录状态</td><td style="height:32px;width:300px;font-size:22px">游玩状态将被更新</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="FinishRecord()">确定</button>
            </div>

        </div>
    </div>
</div>

</body>
</html>